package com.rui.study.algorithm.BinarySearch_2_二分查找变体之第一个指定的值;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2018-11-12 14:49
 **/
public class BinarySearch2 {

    public static int search(int[] a, int value) {
        int low = 0;
        int high = a.length - 1;
        while (low <= high) {
            int mid = low + ((high - low) >> 1);
            if (value <= a[mid]) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        if (low < a.length && a[low] == value)
            return low;
        else
            return -1;
    }
}
